package com.koron.ticket.line.work.workticket.service.impl;


import cn.hutool.core.collection.CollUtil;
import com.koron.ticket.line.work.workticket.bean.po.LineTicketOrder;
import com.koron.ticket.line.work.workticket.mapper.LineTicketOrderMapper;
import com.koron.ticket.line.work.workticket.service.LineTicketOrderService;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线路工作票工单信息(LineTicketOrder)表服务实现类
 *
 * @author jzp
 * @since 2023-02-03 10:12:59
 */
@Service
public class LineTicketOrderServiceImpl implements LineTicketOrderService {

    /**
     * 通过ID查询单条数据
     *
     */
    @Override
    @TaskAnnotation("getById")
    public LineTicketOrder getById(SessionFactory factory, String id) {
        LineTicketOrderMapper mapper = factory.getMapper(LineTicketOrderMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     *
     */
    @Override
    @TaskAnnotation("list")
    public List<LineTicketOrder> list(SessionFactory factory, LineTicketOrder lineTicketOrder) {
        LineTicketOrderMapper mapper = factory.getMapper(LineTicketOrderMapper.class);
        return mapper.selectList(lineTicketOrder);
    }

    @Override
    @TaskAnnotation("listByTicketId")
    public List<LineTicketOrder> listByTicketId(SessionFactory factory, String ticketId) {
        LineTicketOrder lineTicketOrder = new LineTicketOrder();
        lineTicketOrder.setWorkTicketId(ticketId);
        return list(factory, lineTicketOrder);
    }

    /**
     * 新增数据
     *
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, LineTicketOrder lineTicketOrder) {
        LineTicketOrderMapper mapper = factory.getMapper(LineTicketOrderMapper.class);
        return mapper.insertOrUpdate(lineTicketOrder) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<LineTicketOrder> lineStaffs) {
        if (CollUtil.isEmpty(lineStaffs)) {
            return false;
        }
        LineTicketOrderMapper mapper = factory.getMapper(LineTicketOrderMapper.class);
        return mapper.insertOrUpdateBatch(lineStaffs) > 0;
    }

    /**
     * 修改数据
     *
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, LineTicketOrder lineTicketOrder) {
        LineTicketOrderMapper mapper = factory.getMapper(LineTicketOrderMapper.class);
        return mapper.update(lineTicketOrder) > 0;
    }

    /**
     * 通过主键删除数据
     *
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        LineTicketOrderMapper mapper = factory.getMapper(LineTicketOrderMapper.class);
        return mapper.hidden(id) > 0;
    }

    @Override
    @TaskAnnotation("removeByTicketId")
    public boolean removeByTicketId(SessionFactory factory, String ticketId) {
        LineTicketOrderMapper mapper = factory.getMapper(LineTicketOrderMapper.class);
        return mapper.removeByTicketId(ticketId) > 0;
    }

}
